import 'dart:convert';

LoginUser loginUserFromJson(String str) => LoginUser.fromJson(json.decode(str));

String loginUserToJson(LoginUser data) => json.encode(data.toJson());

class LoginUser {
  final String token;
  final UserInfo userInfo;

  LoginUser({
    required this.token,
    required this.userInfo,
  });

  factory LoginUser.fromJson(Map<String, dynamic> json) {
    return LoginUser(
      token: json['token'] as String,
      userInfo: UserInfo.fromJson(json['userInfoDto'] as Map<String, dynamic>),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'token': token,
      'userInfoDto': userInfo.toJson(),
    };
  }
}

class UserInfo {
  final String userId;
  final String? username;
  final int? registerStatus;
  final String? nickname;
  final String? avatar;
  final String? petName;
  final int? isShow;
  final int? teenagerStatus;
  final String? domicile;
  final List<int>? registerProcessList;
  final List<dynamic>? graduationSchools;
  final String? industryName;
  final Map<String, dynamic>? enterpriseDto;
  final UserGrowthLevel? userGrowthLevel;

  UserInfo({
    required this.userId,
    this.username,
    this.registerStatus,
    this.nickname,
    this.avatar,
    this.petName,
    this.isShow,
    this.teenagerStatus,
    this.domicile,
    this.registerProcessList,
    this.graduationSchools,
    this.industryName,
    this.enterpriseDto,
    this.userGrowthLevel,
  });

  factory UserInfo.fromJson(Map<String, dynamic> json) {
    return UserInfo(
      userId: json['userId'] as String,
      username: json['username'] as String?,
      registerStatus: json['registerStatus'] as int?,
      nickname: json['nickname'] as String?,
      avatar: json['avatar'] as String?,
      petName: json['petName'] as String?,
      isShow: json['isShow'] as int?,
      teenagerStatus: json['teenagerStatus'] as int?,
      domicile: json['domicile'] as String?,
      registerProcessList: (json['registerProcessList'] as List<dynamic>?)!
          .map((e) => e as int)
          .toList(),
      graduationSchools: json['graduationSchools'] as List<dynamic>,
      // 原始字段是空数组
      industryName: json['industryName'] as String,
      enterpriseDto: json['enterpriseDto'] as Map<String, dynamic>,
      userGrowthLevel: UserGrowthLevel.fromJson(
          json['userGrowthLevelDict'] as Map<String, dynamic>),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'userId': userId,
      'username': username,
      'registerStatus': registerStatus,
      'nickname': nickname,
      'avatar': avatar,
      'petName': petName,
      'isShow': isShow,
      'teenagerStatus': teenagerStatus,
      'domicile': domicile,
      'registerProcessList': registerProcessList,
      'graduationSchools': graduationSchools,
      'industryName': industryName,
      'enterpriseDto': enterpriseDto,
      'userGrowthLevelDict': userGrowthLevel?.toJson(),
    };
  }
}

class UserGrowthLevel {
  final String id;
  final int growthValue;
  final int level;
  final String image;

  UserGrowthLevel({
    required this.id,
    required this.growthValue,
    required this.level,
    required this.image,
  });

  factory UserGrowthLevel.fromJson(Map<String, dynamic> json) {
    return UserGrowthLevel(
      id: json['id'] as String,
      growthValue: json['growthValue'] as int,
      level: json['level'] as int,
      image: json['image'] as String,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'growthValue': growthValue,
      'level': level,
      'image': image,
    };
  }
}
